package org.smart4j.chapter2.service;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smart4j.chapter2.helper.DataBaseHelper;
import org.smart4j.chapter2.model.Customer;

import java.sql.*;
import java.util.List;
import java.util.Map;


/**
 * 提供客户数据服务
 *
 * @author zhang
 * @create 2016-10-26-10:51
 */

public class CustomerService {

    private final static Logger LOGGER = LoggerFactory.getLogger(CustomerService.class);


    /**
     * 客户列表
     */
    public List<Customer>  getCustomerList(){
        String sql = "SELECT * FROM CUSTOMER";
        return DataBaseHelper.queryEntityList(Customer.class, sql);
    }

    /**
     * 获取客户
     */
    public Customer getCustomer(Long id){
        String sql = "SELECT * FROM CUSTOMER WHERE id = ?";
        return DataBaseHelper.queryEntity(Customer.class, sql, id);
    }

    /**
     * 创建客户
     */
    public  Boolean createCustomer(Map<String, Object> fieldMap){
        return DataBaseHelper.insertEntity(Customer.class, fieldMap);
    }


    /**
     * 更新客户
     */
    public Boolean updateCustomer(Long id, Map<String, Object> fieldMap){
        return DataBaseHelper.updateEntity(Customer.class, fieldMap, id);
    }

    /**
     * 删除客户
     */
    public Boolean deleteCustomer(Long id){
        return DataBaseHelper.deleteEntity(Customer.class, id);
    }
}
